import logging

from flask import current_app,render_template
from flask import session

from info import redis_store

from new_product.info.models import User
from . import index_blue
@index_blue.route('/',methods=['POST','GET'])
def index1():
    # redis_store.set('name','laowang')
    # print(redis_store.get('name'))
    #
    # session['product']='lenove'
    # print(session.get('product'))




    # 使用日志模块输出内容
    # logging.debug("调试信息")
    # logging.info("详细信息")
    # logging.warning("警告信息")
    # logging.error("错误信息")
    #
    # # 使用current_app输出日志信息,和上面输出比较:有华丽分割线
    # current_app.logger.debug("调试信息2")
    # current_app.logger.info("详细信息2")
    # current_app.logger.warning("警告信息2")
    # current_app.logger.error("错误信息2")

    # 获取用户登陆状态
    user_id = session.get("user_id")

    # 获取用户登陆数据
    user = None
    if user_id:
        try:
            user = User.query.get(user_id)
            # user = User.query.filter(user_id).first()
        except Exception as e:
            current_app.logger.error(e)



    data = {
        "user_info": user.to_dict() if user else "",
        # "click_news_list": click_news_list,
        # "category_list": category_list
    }
    return render_template("news/index.html", data=data)







@index_blue.route('/favicon.ico')
def web_logo():
    return current_app.send_static_file('news/favicon.ico')